package applet.admin.components.attendees;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.border.BevelBorder;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;

import sql.SQLInterface;

import data.CMSRes;
import data.account.attendee.AttendeeAccount;
import data.account.attendee.AttendeeTable;
import applet.misc.graphics.AdminBackgroundPanel;

public class CMSAdminAttendeesView extends AdminBackgroundPanel
{
	private static final long serialVersionUID = -6192116157598539741L;
	
	private AttendeeTable attendeeTable;
	private JButton viewButton;
	
	public CMSAdminAttendeesView()
	{
		super(new GridBagLayout());
		setBorder(new EmptyBorder(25, 25, 25, 25));
		
		defineComponents();
		JPanel attendeeDialog = new JPanel(new BorderLayout());
		attendeeDialog.setBorder(new BevelBorder(BevelBorder.RAISED));
		
				JPanel titlePane = new JPanel(new BorderLayout());
				titlePane.setBackground(CMSRes.Colors.get("Admin Color Medium"));
				titlePane.setBorder(new EmptyBorder(10, 10, 10, 10));
					JLabel title = new JLabel("Conference Events:");
					title.setFont(title.getFont().deriveFont(Font.BOLD));
					titlePane.add(title, BorderLayout.WEST);
				attendeeDialog.add(titlePane, BorderLayout.NORTH);
				
			attendeeDialog.add(getContentPanel(), BorderLayout.CENTER);
		add(attendeeDialog);
	}
	
	public void defineComponents()
	{
		viewButton = new JButton("View Attendee");
		viewButton.setPreferredSize(new Dimension(200, 30));
		viewButton.setFont(viewButton.getFont().deriveFont(Font.BOLD));
		viewButton.addActionListener(new ViewListener());
		
		attendeeTable = new AttendeeTable(SQLInterface.getAttendeeList());
		//attendeeTable.setPreferredSize(new Dimension(500, 300));
	}
	
	private JPanel getContentPanel()
	{
		JPanel panel = new JPanel(new BorderLayout());
		panel.setBorder(new CompoundBorder(new BevelBorder(BevelBorder.LOWERED), 
				new EmptyBorder(5, 5, 5, 5)));
			JPanel layoutHelper = new JPanel(new BorderLayout());
			layoutHelper.setPreferredSize(new Dimension(500, 300));
			layoutHelper.setBorder(new EmptyBorder(5, 5, 5, 5));
			layoutHelper.add(new JScrollPane(attendeeTable), BorderLayout.CENTER);
		panel.add(layoutHelper, BorderLayout.CENTER);
			layoutHelper = new JPanel(new BorderLayout());
			layoutHelper.setBorder(new EmptyBorder(5, 5, 5, 5));
			layoutHelper.add(viewButton, BorderLayout.EAST);
		panel.add(layoutHelper, BorderLayout.SOUTH);
		return panel;
	}
	
	private class ViewListener implements ActionListener {
		@Override public void actionPerformed(ActionEvent e)
		{
			AttendeeAccount attendee = attendeeTable.getSelected();
			if(attendee != null)
			{
				AttendeeDialog dialog = new AttendeeDialog(attendee);
				dialog.setLocationRelativeTo(null);
				dialog.setVisible(true);
			}
		} }
}